package controllers;

import helpers.CountryHelper;
import helpers.HeaderHelper;
import helpers.ItuneXMLUrlHelper;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import models.Country;
import models.Software;

public class Countries extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) 
		throws IOException {
		
		response.setHeader("Cache-Control", "public, max-age=86400");
		
		response.setCharacterEncoding("UTF-8");
		//Set header page
		HeaderHelper headerHelper = new HeaderHelper();
		headerHelper.setTitle("List country - 1stApp.org");
		headerHelper.setKeywords("1stApp, free iphone, free itouch, free ipad, many country, paid iphone, paid ipad, top app, top free, iphone, ipad, itouch");
		headerHelper.setDescription("Visitor top free apps iphone, paid apps iphone, free app ipad, paid app ipad on many country");
		headerHelper.setOgite_name("List top app in many countries - 1stApp.org");
		headerHelper.setOgtitle("List top app in many countries");
		headerHelper.setOgurl("http://www.1stapp.org/countries");
		
		//Set variable
		ArrayList<Country> countries = (ArrayList<Country>) CountryHelper.getCountries();
		System.out.println(countries.get(0).getName());
		request.setAttribute("headerHelper", headerHelper);
		request.setAttribute("countries", countries);
		try {
			request.getRequestDispatcher("/pages/countries.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
